package org.zyl.support.response;

import java.util.HashMap;
import java.util.Map;

public enum ResponseCode {
	SUCCESS(200, "操作成功"), 
	REQUEST_NOT(100, "参数不合法"), 
	LOGIN_TIMEOUT(101, "登录超时"), 
	NOT_AUTH(102, "无权限"), 
	OPERATE_ERROR(300, "操作不合法"), 
	OPERATE_NOT_REPEAT_DATA(301, "不能重复提交数据"), 
	OPERATE_DATA_TO_LANG(302, "数据长度超限, 无法继续新增数据"), 
	SEND_SMS_VALIDATE_ERROR(40,"短信验证码错误"), 
	CODE_VALIDATE_ERROR(41,"验证码错误"), 
	OLD_PWD_ERROR(5, "原密码不正确"), 
	ACCOUNT_DISABLE(6,"账号已停用"), 
	USERNAME_PASSWORD_ERROR(7, "用户名或密码错误"), 
	ACCOUNT_ALREADY(71, "账户已经存在"), 
	QUERY_NO_DATAS(8, "未查询到数据"),
	ERROR(500, "操作失败"),
	ERROR_SERVICE_NOT_EXIST(501, "服务不存在"),
	;

	ResponseCode(Integer code, String value) {
		this.code = code;
		this.value = value;
	}

	private Integer code;
	private String value;

	public String getText() {
		return value;
	}

	public Integer getCode() {
		return code;
	}

	private static Map<Integer, ResponseCode> MAPPING = new HashMap<Integer, ResponseCode>();

	static {
		for (ResponseCode model : ResponseCode.values()) {
			MAPPING.put(model.getCode(), model);
		}
	}

	public static ResponseCode forCode(int code) {
		return MAPPING.get(code);
	}

	public static ResponseCode forText(String text) {
		for (ResponseCode model : ResponseCode.values()) {
			if (model.getText().equals(text)) {
				return model;
			}
		}
		return null;
	}
}